home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#11 (Aug 86)
/
pascal
/
RegMDEF Source
/
RegMDEFGlue.Asm
< prev
next >
Wrap
Assembly Source File
|
1986-06-12
|
3KB
|
105 lines
;################################################################################
;# #
;# procedure GetItemKey(theMenu : MenuHandle; #
;# theItem : Integer; #
;# var theChar : Char); #
;# #
;#------------------------------------------------------------------------------#
;# #
;# This assembly proc returns the current command key which is assigned #
;# to theItem. #
;# #
;################################################################################
;------------------------------------ Equates -----------------------------------
; menuinfo data structure
menuID equ 0 ; unique id for menu bar [word]
menuWidth equ 2 ; menu Width [word]
menuHeight equ 4 ; menu Height [word]
menuDefHandle equ 6 ; menu definition proc [handle]
menuEnable equ $A ; enable flags, one bit/item [long]
menuData equ $E ; menu item string [string]
menuBlkSize equ $E ; size of a menu block plus dataString
; menu string data structure
itemIcon equ 0 ; icon byte
itemCmd equ 1 ; command key byte
itemMark equ 2 ; checkmark character byte
itemStyle equ 3 ; style byte
.Trap _CountMItems $A950 ; trap word
;------------------------------------ XREF's ------------------------------------
xdef GetItemKey ; so the linker will find us
;----------------------------------- Entrance -----------------------------------
GetItemKey:
link A6,#0 ; create new stack frame
movem.l A0-A4/D0-D3,-(SP) ; save registers
;------------------------------- Pop Parameters ---------------------------------
clr.l D2 ; make sure it is empty
clr.l D1 ; ditto...
clr.l D0 ; ditto...
clr.w -(SP) ; make room for result
move.l 14(A6),-(SP) ; push MenuHandle
_CountMItems ; how many are in this menu?
move.w (SP)+,D3 ; pop result
move.l 14(A6),A4 ; fetch the menu handle
move.w 12(A6),D1 ; fetch the item number
movea.l 8(A6),A3 ; fetch ptr to the char Ptr(word)
cmp.w D1,D3 ; is num Of Menu Items < theItem
blt BadItem ; yep, exit
;------------------------------ Find the Cmd Key --------------------------------
move.l (A4),A4 ; get menu ptr
lea menuData(A4),A4 ; now A4 points to the menu title
move.b (A4),D2 ; get length of menu title
add.b #1,D2 ; skip length byte
; (A4,D2) now points to the first menu items title (length byte)
nextItem:
sub.b #1,D1 ; decrement count
beq GotItem ; if 0, return its cmd char
move.b (A4,D2),D0 ; get length of the title
add D0,D2 ; and skip it
add #5,D2 ; skip the item attributes & length byte
bra nextItem ; and look at the next item
;-------------------------------- Got the Item ----------------------------------
GotItem:
move.b (A4,D2),D0 ; get length of title
add D0,D2 ; and skip it
add #1,D2 ; skip length byte, too...
clr.w D0 ; make sure its empty
move.b itemCmd(A4,D2),D0 ; get the key equivalent
move.w D0,(A3) ; and return it
bra Exit ; and exit
;-------------------------------- No Item Found ---------------------------------
BadItem:
clr.w (A3) ; return no cmd char and exit
;------------------------------- Clean Up & Exit --------------------------------
Exit:
movem.l (SP)+,A0-A4/D0-D3 ; restore registers
unlk A6 ; restore stack frame
movea.l (SP)+,A0 ; save return address
adda.l #10,SP ; clean up stack
jmp (A0) ; ... and return